// pages/all_data/all_data.js
var wxCharts = require('../../../../utils/wxcharts.js');
var app = getApp();
var lineChart = null;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabList: ['患者数', '专家数', '产品数', '套餐数', '订单数'],
        tab_index: 0,
        date_index: 0,
        windowWidth: "",

    },
    tab_chose: function (e) {
        var index = e.currentTarget.dataset.index
        this.setData({
            tab_index: index
        })
        this.getData();
    },
    lab_chose: function (e) {
        var index = e.currentTarget.dataset.index
        this.setData({
            date_index: index
        })
        this.getData();
    },
    touchHandler: function (e) {
        console.log(lineChart.getCurrentDataIndex(e));
        lineChart.showToolTip(e, {
            // background: '#7cb5ec',
            format: function (item, category) {
                return category + ' ' + item.name + ':' + item.data
            }
        });
    },

    updateData: function () {
        var simulationData = this.createSimulationData();
        var series = [{
            name: '成交量1',
            data: simulationData.data,
            format: function (val, name) {
                return val + '万';
            }
        }];
        lineChart.updateData({
            categories: simulationData.categories,
            series: series
        });
    },
    onLoad: function (e) {
        
        var that = this;
        that.setData({
            windowWidth: wx.getSystemInfoSync().windowWidth
        })
        that.getData();

    },
    getData: function (res) {
        var that = this;
        app.util.request({
            'url': "entry/wxapp/regin.hospital_detail",
            data: {
                date_index: that.data.date_index,
                index: that.data.tab_index,
                openid: wx.getStorageSync('openid')
            },
            success: function (res) {
                var list = res.data.list;
                var datas = res.data.counts;
                var date = res.data.date;
                that.setData({
                    list: list,
                    today: res.data.today,
                    week: res.data.week,
                    month: res.data.month,
                    count: res.data.count,
                    datas: datas,
                    date: date
                })
                lineChart = new wxCharts({
                    canvasId: 'lineCanvas',
                    type: 'line',
                    categories: date,
                    animation: true,
                    // background: '#f5f5f5',
                    series: [{
                        name: '成交量',
                        data: datas,
                        format: function (val, name) {
                            return val.toFixed(2);
                        }
                    }],
                    xAxis: {
                        disableGrid: true,
                    },
                    yAxis: {
                        disabled: true,
                        title: '',
                        min: 0
                    },
                    width: that.data.windowWidth,
                    height: 200,
                    dataLabel: false,
                    dataPointShape: true,
                    extra: {
                        lineStyle: 'curve'
                    }
                });
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})